package com.dq.domain.message.oneself;

import com.dq.vo.baseVo.VO;
import com.dq.domain.sys.user.user.base.SysUser;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * @author liuhui
 * @date 2019/11/22 0022 10:31:21
 */
@Data
@Entity
@ApiModel("通知消息")
public class NoticeMessage extends Message{

    @ApiModelProperty("通知内容")
    @Column(columnDefinition = "text")
    @NotBlank
    protected String content;

    @ApiModelProperty("消息接受者，员工/顾客")
    @ManyToOne
    public SysUser caseUser;


    @ApiModelProperty("消息接受者，员工/顾客集合")
    @Transient
    protected List<Long> caseUserIds = new ArrayList<>();

    @ApiModelProperty("接收者类型：(员工/顾客)")
    @Enumerated(EnumType.ORDINAL)
    @NotNull
    protected SubscribeMessage.UserType userType;

    @Data
    @ApiModel("视图")
    public static class Vo implements VO {
        protected Long id;
        @ApiModelProperty("通知标题")
        protected String theme;
        @ApiModelProperty("通知内容")
        protected String content;
        @ApiModelProperty("消息接受者，员工/顾客")
        public Long caseUserId;
        @ApiModelProperty("消息接受者，员工/顾客")
        public String caseUserName;

        @ApiModelProperty("未读/已读")
        public String messageStatusEn;
        @ApiModelProperty("未读/已读")
        public String messageStatusCn;
        @ApiModelProperty("消息类型")
        public String messageTypeEn;
        @ApiModelProperty("消息类型")
        public String messageTypeCn;

        @ApiModelProperty("消息类型")
        public String createTime;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
       vo.id = this.id;
       vo.theme = this.theme;
       vo.content = this.content;
       vo.caseUserId = this.getCaseUser() == null ? null : this.getCaseUser().getId();
       vo.caseUserName = this.getCaseUser() == null ? null : this.getCaseUser().getUserRealcName();

       vo.messageStatusEn = this.getMessageStatus().toString();
       vo.messageStatusCn = this.getMessageStatus().name;
       vo.messageTypeEn = this.getMessageType().toString();
       vo.messageTypeCn = this.getMessageType().name;

        vo.createTime = fmt(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);

        return vo;
    }
}
